from fastmcp import FastMCP
import datetime
from Calculator import Calculator
from Logger import logger

# Initialize FastMCP server
mcp = FastMCP("Calculator")

calculator_01=Calculator(1)

d=datetime.datetime.now()
T=d.strftime('%Y-%m-%d %H-%M-%S')
T_0=T+'_Calculator_Data'+'.log'


f=open(T_0,mode="at")

# Initialize FastMCP server
mcp = FastMCP("Calculator")

@mcp.tool()
async def plus(a,b)->float:
    """实现两个数的加法，传入参数a和参数b,

    Args:
        a:被加的数
        b:加上的数
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: plus, a: {a}, b: {b}, Result: {calculator_01.plus(a,b)}")
    f.write("{0}+{1}={2}".format(a,b,calculator_01.plus(a,b)))
    return calculator_01.plus(a,b)

@mcp.tool()
async def minus(a,b)->float:
    """实现两个数的减法，传入参数a和参数b,

    Args:
        a:被减的数
        b:减去的数
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: minus, a: {a}, b: {b}, Result: {calculator_01.minus(a,b)}")
    f.write("{0}-{1}={2}".format(a,b,calculator_01.minus(a,b)))
    return calculator_01.minus(a,b)

@mcp.tool()
async def multiplication(a,b)->float:
    """实现两个数的乘法，传入参数a和参数b,

    Args:
        a:被乘的数
        b:乘上的数
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: multiplication, a: {a}, b: {b}, Result: {calculator_01.multiplication(a,b)}")
    f.write("{0}*{1}={2}".format(a,b,calculator_01.multiplication(a,b)))
    return calculator_01.multiplication(a,b)

@mcp.tool()
async def division(a,b)->float:
    """实现两个数的除法，传入参数a和参数b,

    Args:
        a:被除的数
        b:除去的数
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: division, a: {a}, b: {b}, Result: {calculator_01.division(a,b)}")
    f.write("{0}/{1}={2}".format(a,b,calculator_01.division(a,b)))
    return calculator_01.division(a,b)

@mcp.tool()
async def sine(a)->float:
    """计算一个数的正弦，传入参数a,

    Args:
        a:被计算正弦的数(弧度制)
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: sine, a: {a}, Result: {calculator_01.sine(a)}")
    f.write("sin {0}={1}".format(a,calculator_01.sine(a)))
    return calculator_01.sine(a)

@mcp.tool()
async def cosine(a)->float:
    """计算一个数的余弦，传入参数a,

    Args:
        a:被计算余弦的数(弧度制)
    """
    logger.info(f"ID: {calculator_01.ID}, Operation: cosine, a: {a}, Result: {calculator_01.cosine(a)}")
    f.write("cos {0}={1}".format(a,calculator_01.cosine(a)))
    return calculator_01.cosine(a)

if __name__ == "__main__":
    # Initialize and run the server
    logger.info("__main__"+T)
    mcp.run()

